package bibbletex.views;

import java.util.Collections;
import java.util.List;

import bibbletex.models.Reference;

public class CollaborationView {
	public static String public_link(bibbletex.models.Collaboration c) {
		if (c != null)
			return new String("/collaboration/show.jsp?cid=") + c.getPublic_id();
		else
			return null;
	}
	
	public static String private_link(bibbletex.models.Collaboration c) {
		if (c != null)
			return new String("/collaboration/show.jsp?cid=") + c.getId();
		else
			return null;
	}
	
	public static String possible_action(boolean is_editable) {
		if (is_editable)
			return new String("Add");
		else
			return new String("Suggest");
	}
	
	public static String show_library_parameter(boolean library){
		String parameter;
		if (library == true)
			parameter = "show_references=library";
		else
			parameter = "show_references=suggestions";
		
		return parameter;
	}

	
	public static String generate_url(boolean library){
		String parameter0 = show_library_parameter(library);
		String url = new String("show.jsp?"+parameter0);
		return url;
	}
	
	public static String generate_querystring(boolean library, String sorting, String previous_sorting){
		String parameter0 = show_library_parameter(library);
		String url = new String(parameter0);
		return url;
	}
	
	public static void sort(List<Reference> refs, String sorting){
		if (sorting != null)
		{
			if (sorting.equals("authorASC"))
				Collections.sort(refs, new Reference.CompareByAuthorASC());	
			else if (sorting.equals("authorDESC"))
				Collections.sort(refs, new Reference.CompareByAuthorDESC());
			else if (sorting.equals("titleASC"))
				Collections.sort(refs, new Reference.CompareByTitleASC());
			else if (sorting.equals("titleDESC"))
				Collections.sort(refs, new Reference.CompareByTitleDESC());
			else if (sorting.equals("typeASC"))
				Collections.sort(refs, new Reference.CompareByTypeASC());
			else if (sorting.equals("typeDESC"))
				Collections.sort(refs, new Reference.CompareByTypeDESC());
			else if (sorting.equals("relevanceASC"))
				Collections.sort(refs, new Reference.CompareByRelevanceASC());
			else if (sorting.equals("relevanceDESC"))
				Collections.sort(refs, new Reference.CompareByRelevanceDESC());
		}
	}
	
	public static String sortArrow(String field, String sorting){
		String arrow = "";
		if (field != null && sorting != null)
		{
			if (sorting.contains(field)){
				arrow = "&#x25BE;";
				if (sorting.contains("ASC"))
					arrow = "&#x25B4;";
				else 
					arrow = "&#x25BE;";
			}
			else
				arrow = "";
		}
		else
			arrow = "";
		
		return arrow;
	}
}
